package com.mms.utsc.smartnet;

import java.util.ArrayList;
import java.util.concurrent.ExecutionException;

import android.app.Activity;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.ListView;
import android.widget.Toast;

public class CoursesMenu extends ListActivity{
	
	ProgressDialog loadingCoursePageDialog;
	private static String[][] courseIDMap = null;
	ArrayList<MenuListItem> menuList = new ArrayList<MenuListItem>();

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		loadingCoursePageDialog = ProgressDialog.show(this, "Loading...", "Loading courses - Please wait...");

		initCourseMenuList();
		
		// instead of setContentView
		setListAdapter(new ListViewImageTextAdapter(CoursesMenu.this, this.menuList, R.layout.course_menu_item));
	}
	
	private void initCourseMenuList(){
		DBHandler courseDBHandler = new DBHandler(loadingCoursePageDialog, this);
		try {
			this.menuList = courseDBHandler.getCourseList();
			loadingCoursePageDialog.dismiss();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		super.onListItemClick(l, v, position, id);

		// String classToLaunchStr = classMap[position][1];
		startActivity(menuList.get(position).getIntentToLaunch(CoursesMenu.this));
	}
}
